package com.atguigu.lease.web.app.custom.config;

import com.atguigu.lease.web.app.custom.interceptor.AuthenticationInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfiguration implements WebMvcConfigurer {
//这是一个springmvc的配置类，用于注册和配置拦截器
    @Value("${app.auth.path-patterns.include}")//是 Spring 的 SpEL 表达式，
    // 用于指导拦截器去从配置文件中读取属性值。
    private String[] includePathPatterns;

    @Value("${app.autu.path-patterns.exclude}")//是 Spring 的 SpEL 表达式，用于从配置文件中读取属性值。
    private String[] excludePathPatterns;

    @Autowired
    private AuthenticationInterceptor authenticationInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(this.authenticationInterceptor)
                .addPathPatterns(includePathPatterns)
                .excludePathPatterns(excludePathPatterns);
    }
}
